package com.jtech.dribbble.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jtech.dribbble.R;
import com.jtech.dribbble.contract.TestContract;
import com.jtech.dribbble.presenter.TestPresenter;
import com.jtech.dribbble.view.fragment.base.BaseFragment;

import butterknife.Bind;

/**
 * 测试用fragment
 * Created by wuxubaiyang on 16/4/16.
 */
public class TestFragment extends BaseFragment implements TestContract.View {

    private static final String KEY_TOAST = "toast";

    @Bind(R.id.textview)
    protected TextView textView;

    private TestPresenter testPresenter;

    /**
     * 创建视图的方法
     *
     * @param inflater
     * @param container
     * @return
     */
    @Override
    public View createView(LayoutInflater inflater, ViewGroup container) {
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

    /**
     * 入口方法
     *
     * @param bundle
     */
    @Override
    public void init(Bundle bundle) {
        //在这里可以解析newinstance传进来的参数
        String toast = bundle.getString(KEY_TOAST);
        textView.setText(toast);
    }

    /**
     * 创建对象，不通过主构造
     *
     * @return
     */
    public static TestFragment newInstance(String toast) {
        Bundle args = new Bundle();
        //添加参数
        args.putString(KEY_TOAST, toast);
        //实例化对象
        TestFragment fragment = new TestFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void setPresenter(TestPresenter presenter) {
        this.testPresenter = presenter;
    }
}